package cn.est.controller;
import cn.est.pojo.Evaluate;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.EvaluateService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/evaluate")
public class EvaluateController {

    @Resource
    private EvaluateService evaluateService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<Evaluate> searchEvaluate(@RequestParam Map<String,Object> param) {
        Page<Evaluate> evaluatePage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            evaluatePage  = evaluateService.queryEvaluatePageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return evaluatePage;
    }

    @RequestMapping("/saveOrUpdateEvaluate")
    @ResponseBody
    public Result saveOrUpdateEvaluate(Evaluate evaluate){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(evaluate.getId())){
                flag=evaluateService.qdtxAddEvaluate(evaluate);
            }else{
                flag=evaluateService.qdtxModifyEvaluate(evaluate);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getEvaluateById")
    @ResponseBody
    public Result getEvaluateById(Long id){
        Result result= ResultUtils.returnSuccess();
        Evaluate evaluate=null;
        try {
            evaluate=evaluateService.getEvaluateById(id);
            result.setData(evaluate);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveEvaluate")
    @ResponseBody
    public Result batchRemoveEvaluate(String ids){
        Integer flag=0;
        try {
            flag=evaluateService.qdtxBatchDeleteEvaluate(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeEvaluateById")
    @ResponseBody
    public Result removeEvaluateById(Long id){
        Integer flag=0;
        try {
            flag=evaluateService.qdtxDeleteEvaluateById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
